<template>
	<view class="page">
		<u-navbar :title="company.name" border placeholder @leftClick="$utils.back()">
		</u-navbar>
		<view class="tabber_box">
			<home @clickTabbar='clickTabbar' :shop='shop' :loading='loading' v-if="value==0"></home>
			<activePage v-else-if='value==1' />
			<my v-else-if='value==2'></my>
		</view>
		<view>

			<u-tabbar :value="value" fixed placeholder safeAreaInsetBottom>
				<u-tabbar-item text="工地" icon="home" @click="clickTabbar"></u-tabbar-item>
				<u-tabbar-item text="施工监督" icon="tags" @click="clickTabbar" :badge="badge"></u-tabbar-item>
				<u-tabbar-item text="我的" icon="account" @click="clickTabbar"></u-tabbar-item>
			</u-tabbar>
		</view>
	</view>
</template>

<script>
	import my from './components/my.vue'
	import home from './components/home.vue'
	import activePage from './components/activePage.vue'
	export default {
		components: {
			my,
			home,
			activePage
		},
		data() {
			return {
				badge: uni.getStorageSync('unAuthorizedCount'),
				value: 0,
				shop: {},
				loading: true,

			}
		},
		computed: {
			company() {
				return {
					name: uni.getStorageSync('companyName'),
					logo: uni.getStorageSync('companyLogo'),
				}
			}
		},
		onLoad() {
			if (uni.getStorageSync('token')) {
				uni.showLoading({
					title: '加载中...'
				})
				this.$api_company.Shop.All().then(res => {
					this.loading = false
					uni.hideLoading()
					if (!res.data.user.companies.length) {
						uni.reLaunch({
							url: '/register/index'
						})
						return
					}
					// if(res.data.user.companies.length){
					// 	const shop = res.data.user.companies[0]
					// 	if(shop.is_expired){
					// 		uni.$u.toast('店铺过期请先购买')
					// 		setTimeout(()=>{
					// 			uni.reLaunch({
					// 				url:'/pay/list'
					// 			})
					// 		},500)
					// 	}
					// }
					this.shop = res.data.user.companies[0]
					uni.setStorageSync('user', res.data.user);
				}).catch(err => {
					uni.hideLoading()
					uni.$u.toast(err.message)
				})
			} else {
				this.loading = false
			}

		},
		methods: {
			clickTabbar(e) {
				if(e==1){
					this.badge=0
					uni.setStorageSync('unAuthorizedCount', 0);
				}
				this.value = e

			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		display: flex;
		height: 100vh;
		flex-direction: column;
		box-sizing: border-box;
		background: url('@/static/image/bg.png');
	}

	.tabber_box {
		flex: 1;
		overflow: hidden;
	}

	::v-deep .uicon-plus-circle {
		font-size: 80rpx !important;
	}
</style>